<template>
    <view>
        <u-navbar :title=title @rightClick="onGoBack" @leftClick="onGoBack" titleStyle="font-size:18px"  :autoBack="!isCustomBack"/>
        <!-- 等高元素，防止塌陷 -->
        <view :style="{ height: safeAreaInsets.top + 44 +'px' }" />
    </view>
</template>

<script>
import { confirmYes,  } from "@/utils/PrjUtils";

export default {
    name: "BasicNavbar",
    props: {
        title: {
            type: String,
            required: true,
            default: '新页面'
        },
        canBack: {
            type: Boolean,
            required: false,
            default: false
        },
        bgColor: {
            type: String,
            required: false,
            default: '#fff'
        },
        titleBg: {
            type: String,
            required: false,
            // default: 'rgba(0,0,0,0)'
            default: '#FFF'
        },
        isCustomBack:{
            type: Boolean,
            required: false,
            default: false
        }
    },
    data() {
        return {
            safeAreaInsets: {},
        }
    },
    beforeMount() {
        uni.getSystemInfo({
            success: (res) => {
                this.safeAreaInsets = res.safeAreaInsets
            }
        })
    },
    methods: {
        // 返回上一页
        onGoBack() {
            if(this.isCustomBack ){
                return this.$emit('cancel');
            }
            if (!this.canBack) return
            if (getCurrentPages().length === 1) {
                confirmYes('上个页面已失效，是否返回至登录页面？', () => {
                    uni.reLaunch({
                        url: '/pages/login/login'
                    })
                })
            } else {
                uni.navigateBack();
            }
        }
    }
}
</script>

<style lang="scss">

</style>
